#include<stdio.h>
#include<stdlib.h>

//版本2:使用动态数组实现
struct Stu
{
  int* a; //指向动态开辟的数组
};
typedef struct Stu Stu;
int main()
{
  Stu* s = (Stu*)malloc(sizeof(Stu));
  s->a = (int*)malloc(sizeof(int)*10); 
  for(int i = 0;i<10;i++)
    s->a[i] = i,printf("%d ",s->a[i]);
  printf("\n");

  //扩容
  int* tmp =(int*)realloc(s->a,sizeof(int)*20);
  if(tmp != NULL)
    s->a = tmp;

  for(int i = 0;i<20;i++)
    s->a[i] = i,printf("%d ",s->a[i]);
  printf("\n"); 

 //最后记得释放空间！！先释放动态开辟的空间 再释放动态开辟的结构体
  free(s->a);
  s->a = NULL;
  free(s);
  s = NULL;
  return 0;
}
